﻿using System;
using GameEngine.Model;
using GameEngine.Model.Data;
using PureMVC.Interfaces;
using PureMVC.Patterns;
using GameEngine.View.Components;

namespace GameEngine.Controller
{
    public class SelectThingCommand<MyIdType, MyBaseUIElementType> : SimpleCommand
        where MyIdType : IComparable<MyIdType>
    {
        override public void Execute(INotification notification)
        {
            var thing = notification.Body as IThingVOId<MyIdType>;
            foreach (var lvl in ModelFacade<MyIdType>.Instance.Game.Levels.Values) {
                foreach (var world in lvl.Worlds) { 
                    if(world.Id.Value.Equals(notification.Type)){
                        var worldDataProxy = ModelFacade<MyIdType>.Helper.GetWorldDataProxy(world);
                        var mapDataProxy = worldDataProxy.Map;
                        var mapMediator = ViewFacade<MyIdType, MyBaseUIElementType>.Helper.GetMapMediator(mapDataProxy);

                        var thingDataProxy = ModelFacade<MyIdType>.Helper.GetThingDataProxy(thing);
                        
                        mapMediator.SelectedItem = thingDataProxy;

                        return;
                    }
                }
            }
        }
    }
}
